import { createRouter, createWebHistory } from 'vue-router'
import { routes } from './routes.js'

const router = createRouter({
  history: createWebHistory(),
  routes
})

router.beforeEach(to => {
  if (!(to.name === 'NotFound')) {
    const isMobile = window.innerWidth <= 768 // 判断视口宽度是否小于 768px (一般的手机视口)
    const isMobileByUserAgent = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) // 判断是否为手机端
    if (!(isMobile || isMobileByUserAgent)) { //如果满足一个有一个
      return ({ name: 'NotFound' })
    }
  }
})

export default router
